How To Build AGAR for ARM


Intro


In this How To we are going to build AGAR 1.4.1 with our GCC/G++ 4.8.2 cross-compiler. I finally started to achieve one of my goals, build my own Linux file system, and then I came across a wall when it came to the user interface. To X or not to X? GTK+? DirectFB? Or one of many third party libraries out there that "can do it all"? I already had exposure to SDL 1.2 and loved the fact that all I needed to do was setup the Linux framebuffer, which is real easy, and you can make games, basic windows (no real window manager here), handle keyboard events, mouse events, joystick events, music, load bmp's and so much more. I was hooked and did not want to complicate my simple project with X or any other library that had a lot of dependencies. Yes, of course I'm sacrificing a little in terms of graphics acceleration and other features. But for me it's just not worth the hassle, if you are like me and have tried to cross-compile these then you know what I'm talking about. At least not now ;-) There was still the issue of widgets that SDL, at least my old version, lacked. That is to say, buttons, windows, checkboxes, textboxes, labels, etc. After quite awhile of research, months, I came across this. Finally! After reading the AGAR docs over and over and over again, I decided this was the library I've been looking for. So, you may have different requirements, or you may want something a little more powerful and/or fancier. But for the ones who want to give AGAR a shot I hope you find this useful and AGAR as well :o) Oh, and do not let the steep learning curve deter you from using it. The online documentation is pretty good although it can be cryptic at times. The examples are a little out of date so when you are in doubt consult the source code.

Tar Balls


Here is a list of source packages that we'll need for the build. You can either download them now or wait 'til later in the How To.
  • agar-1.4.1.tar.gz

AGAR does not have any dependencies, refer to their homepage if you doubt me, but you if you are using AGAR with SDL and the Linux framebuffer you'll want to build AGAR with FreeType font and you'll need SDL. Enough talk, let's get started.

Create a Workspace


I recommend creating a workspace under your /home/<your user>/ directory that is dedicated to this build. So let's fire up your terminal and run the following:
$ export AGAR_SRC=~/workbench/agar/src
$ export AGAR_BUILD=~/workbench/agar/build
$ mkdir -pv ~/workbench/agar
$ mkdir $AGAR_SRC && mkdir $AGAR_BUILD
$ cd $AGAR_SRC

Gather the Sources


Now that we have a workspace created and we are currently in the src directory we can begin bringing down the sources and extracting them.

agar

$ wget http://stable.hypertriton.com/agar/agar-1.4.1.tar.gz
$ tar -pxzf agar-1.4.1.tar.gz

Build Environment


To make things a little smoother let's setup some environment variables:
$ export INSTALLDIR=~/workbench/gcc-g++-4.8.2/arm
$ export PATH=$INSTALLDIR/bin:$PATH
$ export TARGETMACH=arm-none-linux-gnueabi
$ export BUILDMACH=i686-pc-linux-gnu
$ export CROSS=arm-none-linux-gnueabi
$ export CC=${CROSS}-gcc
$ export LD=${CROSS}-ld
$ export AS=${CROSS}-as
$ export CXX=${CROSS}-g++
NOTE: Depending on whether you are using a cross-compiler built from my other wikis you might need to change INSTALLDIR to point to your cross-compiler.

Build AGAR


$ cd agar-1.4.1/
$ export PKG_CONFIG_PATH=/home/<your user>/workbench/freetype/final/lib/pkgconfig:/home/<your user>/workbench/sdl/final/lib/pkgconfig
 
===========================================================================================================================
Fix build issue: "sed -i -e 's,-Werror,,' ./configure" Refer to: http://permalink.gmane.org/gmane.comp.lib.agar.general/698
===========================================================================================================================
 
$ ./configure --prefix=/usr --host=$TARGETMACH --enable-threads --with-freetype=/home/<your user>/workbench/freetype/final/ --with-sdl=/home/<your user>/workbench/sdl/final/
$ make
$ make DESTDIR=/home/<your user>/workbench/agar/final  install

Output


cd into the final directory and output its contents:
$ cd ../final/usr/
$ ls
You should have the following directories:
  • bin
  • include
  • lib
  • man
  • share

Lastly, move the contents of these directories, or the directories themselves if they do not already exist, to your custom Linux file system or dev board. For AGAR, the files should go under /usr.

Usage


To use AGAR all you need to do is set the following in a new terminal/tab:
$ export INSTALLDIR=~/workbench/gcc-g++-4.8.2/arm
$ export PATH=$INSTALLDIR/bin:$PATH
$ export TARGETMACH=arm-none-linux-gnueabi
$ export BUILDMACH=i686-pc-linux-gnu
$ export CROSS=arm-none-linux-gnueabi
$ export CC=${CROSS}-gcc
$ export LD=${CROSS}-ld
$ export AS=${CROSS}-as
$ export CXX=${CROSS}-g++
NOTE: Depending on whether you are using a cross-compiler built from my other wikis you might need to change INSTALLDIR to point to your cross-compiler.

When you're ready to cross-compile your AGAR program:
$ $CC -Wall -Wextra -I/home/<your user>/workbench/agar/final/usr/include <your program>.c -o <your program> `/home/<your user>/workbench/agar/final/usr/bin/agar-config --cflags --libs`
If the above does not work, then try:
$ $CC -Wl,--unresolved-symbols=ignore-all -I/home/<your user>/workbench/agar/final/usr/include <your program>.c -o <your program> `/home/<your user>/workbench/agar/final/usr/bin/agar-config --cflags --libs`
Notice that even though we are going to use this with SDL you did not need to use sdl-config :D AGAR has you covered.

Here I am all excited that I got the build to work, this is for the RPi, I move the libs and binaries over to the RPi, create an example program, move it to the RPi and run it...BAM! Seg fault :-( Using GDB it appeared to be in AG_InitCore (strlen.S:33). That was a show stopper for me, but I hope you did not have this issue, if you did, read on to see my workaround.

Hackity, Hackity, Hack


cd to where you currently have AGAR and bring down the trunk:
$ cd ~/workbench/agar/
$ svn checkout http://dev.hypertriton.com/agar/trunk agar-trunk
$ cd agar-trunk/
 
===============================================================================================================================================
Fix some issues - I was lucky here :P
 
mv mk mk.org
 
cp ../src/agar-1.4.1/mk/ .
 
Change "LIBTOOL=/usr/bin/libtool" to "LIBTOOL=${TOP}/mk/libtool/libtool" in "../agar/agar-trunk/Makefile.config"
 
Change (../agar/agar-trunk/configure:~4027 & 4028):
 
echo "$CC $CFLAGS $TEST_CFLAGS ${SDL_CFLAGS} -o $testdir/conftest conftest.c ${SDL_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${SDL_CFLAGS} -o $testdir/conftest conftest.c ${SDL_LIBS} 2>>config.log
 
to:
 
echo "$CC -Wl,--unresolved-symbols=ignore-all $CFLAGS $TEST_CFLAGS ${SDL_CFLAGS} -o $testdir/conftest conftest.c ${SDL_LIBS}" >>config.log
$CC -Wl,--unresolved-symbols=ignore-all $CFLAGS $TEST_CFLAGS ${SDL_CFLAGS} -o $testdir/conftest conftest.c ${SDL_LIBS} 2>>config.log
 
The above ensures that no matter what SDL test passes ;-) We already know SDL works. Now Make should configure SDL properly
===============================================================================================================================================
 
$ ./configure --prefix=/usr --host=$TARGETMACH --enable-threads --with-freetype=/home/<your user>/workbench/freetype/final/usr/ --with-sdl=/home/<your user>/workbench/sdl/final/usr/ --without-opengl
$ make depend all
$ make DESTDIR=/home/<your user>/workbench/agar/final-trunk install
 
I hope you did not have to go through that :-| I had to do the above hack to get trunk to build for me. You may not have to, so try the build without doing the above and go from there.